package artid.com.arttogo.activity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Window;
import android.view.animation.Animation;
import android.widget.RelativeLayout;

import com.android.volley.VolleyError;

import artid.com.arttogo.R;
import artid.com.arttogo.bean.AppItem;
import artid.com.arttogo.db.Cache;
import artid.com.arttogo.network.VolleyBasic;
import artid.com.arttogo.network.VolleyCallback;
import artid.com.arttogo.network.VolleyData;
import artid.com.arttogo.network.VolleyMap;

/**
 * 闪屏页面
 * 
 * @author
 * 
 */
public class SplashActivity extends Activity {
	private RelativeLayout m;
	// 延迟3秒
	private static final long SPLASH_DELAY_MILLIS = 500;
	
	String shareTime, advTime, whiteListTime, guideTime;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);// 隐藏标题
		setContentView(R.layout.splash_layout);
		m = (RelativeLayout) findViewById(R.id.app_back);
//		test();
		DelyLog();
//		test();
//		handler.sendEmptyMessageDelayed(1, SPLASH_DELAY_MILLIS);
	}
	void test(){
		
		VolleyBasic.getInstance(SplashActivity.this).post(Cache.lotInfo,
				VolleyMap.getInstance().lotInfo("1"), AppItem.class,
				new VolleyCallback() {
					
					@Override
					public void onSuccess(VolleyData vd) {
						// TODO Auto-generated method stub
							Log.e("lotinfo",vd.getJson());
						//List<ArtList> list = (List<ArtList>)vd.getList();
						//if (list.isEmpty()) {
						//	Config.showTip(MoreCollectionsActivity.this, "无数据");
							return;
						//}
						//ArtistInfo list = (ArtistInfo)vd.getData();
					}
					@Override
					public void onError(VolleyError volleyError) {
						// TODO Auto-generated method stub
						
					}
					});
	
	}
	
	void DelyLog(){
		Handler handler = new Handler();
		handler.postDelayed(new Runnable() {
			
			@Override
			public void run() {
				// TODO Auto-generated method stub
				Intent intent = new Intent(SplashActivity.this,
						AdvActivity.class);
				SplashActivity.this.startActivity(intent);
				SplashActivity.this.finish();
			}
		}, 1500);
	}
	protected Animation getAnimation() {
//		Animation anim = new ScaleAnimation(1.0f, 1.2f, 1.0f, 1.2f,
//				Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
//				0.5f);
//		anim.setFillAfter(true);
		Animation anim = new Animation() {
		};
		anim.setDuration(1);
		return anim;
	}
	
	Intent mIntent;
	@SuppressLint("HandlerLeak")
	private Handler handler = new Handler() {
		
		public void handleMessage(Message msg) {
//			if (m==null) {
//				Intent intent = new Intent(SplashActivity.this,
//						MainActivity.class);
//				SplashActivity.this.startActivity(intent);
//				SplashActivity.this.finish();
//				return;
//			}
//			Animation anim = getAnimation();
//			
//			m.startAnimation(anim);
//			
//			anim.setAnimationListener(new AnimationListener() {
//				@Override
//				public void onAnimationStart(Animation animation) {
//					
//				}
//				
//				@Override
//				public void onAnimationRepeat(Animation animation) {
//					
//				}
//				
//				@Override
//				public void onAnimationEnd(Animation animation) {
//					Intent intent = new Intent(SplashActivity.this,
//							MainActivity.class);
//					SplashActivity.this.startActivity(intent);
//					SplashActivity.this.finish();
//				}
//			});
		}
		
	};

	private static void outputLog(String strTAG, String strInfo) {
		Log.i(strTAG, strInfo);
	}
}
